/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.core.spi;

import org.proteusframework.core.api.model.IDisplayableName;
import org.proteusframework.core.util.Assert;


/**
 * Base class used by every type of Proteus plugin provider.
 *
 * @author Tacoma Four
 */
public abstract class AbstractProvider implements IAbstractProvider
{
    /**
     * Immutable displayable name for the plugin.
     */
    private final IDisplayableName dn;

    /**
     * Stores the displayable name of the plugin.
     *
     * @param displayableName Displayable name; must not be null
     */
    protected AbstractProvider(final IDisplayableName displayableName)
    {
        Assert.parameterNotNull(displayableName, "Parameter 'displayableName' must not be null");
        this.dn = displayableName;
    }

    /**
     * Displayable name of the plugin.
     *
     * @return Displayable name
     */
    @Override
    public final IDisplayableName getDisplayableName()
    {
        return dn;
    }

    /**
     * Equality is determined by strictly comparing the {@link #dn} instances.
     *
     * @param o Object to check for equality
     * @return true, if the objects are equal
     */
    @Override
    public final boolean equals(Object o)
    {
        if (this == o)
        {
            return true;
        }
        if (!(o instanceof AbstractProvider))
        {
            return false;
        }

        AbstractProvider that = (AbstractProvider) o;

        if (!dn.equals(that.dn))
        {
            return false;
        }

        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final int hashCode()
    {
        return dn.hashCode();
    }

    @Override
    public final String getFamily()
    {
        return dn.getFamily();
    }

    @Override
    public final String getId()
    {
        return dn.getId();
    }

    @Override
    public final String getRefId()
    {
        return dn.getRefId();
    }
}
